const os = require('os');

// 获取本机的局域网 IP 地址
function getLocalIp() {
  const networkInterfaces = os.networkInterfaces();
  let localIp;

  for (const interface in networkInterfaces) {
    for (const address of networkInterfaces[interface]) {
      if (address.family === 'IPv4' && !address.internal) {
        localIp = address.address;
        break;
      }
    }
    if (localIp) break; // 找到后退出循环
  }
  return localIp || 'localhost'; // 如果没有找到，返回 localhost
}

module.exports = getLocalIp;
